package com.example.dzbsh.controller;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.dzbsh.model.JingshangQingkuang;
import com.example.dzbsh.model.Renyuan;
import com.example.dzbsh.service.JiashuService;
import com.example.dzbsh.service.RenyuanService;
import com.example.dzbsh.util.CreateWord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.dzbsh.service.JingshangQingkuangService;
import com.example.dzbsh.util.CreateXLS;
import com.example.dzbsh.util.JsonResult;
import com.example.dzbsh.util.PageInfo;

@RestController
@RequestMapping("jingshangqingkuang")
public class JingshangQingkuangController {
	
	@Value("${userfilepath}")
	private String userfilepath;
	
	@Resource
    JingshangQingkuangService ddService;
	@Resource
	RenyuanService ddRenyuanService;
	@Resource
	JiashuService ddJiashuService;
	
    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("find_jingshangqingkuang_by_page")
    public JsonResult<?> findJingshangqingkuangByPage(@RequestParam("pageindex") int ppPageIndex,
                                   @RequestParam("pagesize") int ppPageSize){
        try {
            List<Map<String, Object>> mmList=ddService.findJingshangqingkuangByPage(ppPageIndex,ppPageSize);
            Integer mmCount = ddService.getCountByisvalid();
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("JingshangQingkuangList", mmList);
            mmMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmMap);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.getErrorResult("jingshangqingkuang/find_jingshangqingkuang_by_page:error " + e.getMessage());
        }
    }

	@RequestMapping("getcount_by_renyuanid")
	public JsonResult<?> getCountByzhuangtaiAndRenyuanId(@RequestParam("renyuanid") String ppRenyuanID) {
		try {
			return JsonResult.getSuccessResult(ddService.getCountByzhuangtaiAndRenyuanId(ppRenyuanID));
		}catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/getCountByzhuangtaiAndRenyuanId:error " + e.getMessage());
		}
	}

	@RequestMapping("find_jiashu_by_renyuanid_and_leixing")
	public JsonResult<?> findJiashuByRenyuanIdAndLeixing(@RequestParam("renyuanid") String pprenyuanID,@RequestParam("leixing") String ppLeixing){
		try {

			List<Map<String,Object>> mmList = ddService.findJiashuByRenyuanIdAndLeixing(pprenyuanID,ppLeixing);
			List<Map<String,Object>> mmReturnList = new ArrayList<>();
			for (int i = 0; i < mmList.size(); i++) {
				Map<String,Object> mmJiashuMap = mmList.get(i);
				if (mmJiashuMap!=null){
					String mmJiashuId = mmJiashuMap.get("jiashuid")== null ? "" :mmJiashuMap.get("jiashuid").toString();
					List<Map<String,Object>> mmJingshangqingkuangList = ddService.findByJiashuIdAndLeixing(mmJiashuId,ppLeixing);
					mmJiashuMap.put("jingshangqingkuanglist",mmJingshangqingkuangList);
				}
				mmReturnList.add(mmJiashuMap);
			}

			return JsonResult.getSuccessResult(mmReturnList);

		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/findVaildByRenyuanId:error " + e.getMessage());
		}
	}

	@RequestMapping("find_custom_by_deptid")
	public JsonResult<?> findCustomByDeptId(@RequestParam("deptid") String ppDeptId,@RequestParam("truename") String ppTrueName,@RequestParam("renyuanleibie") String ppRenyuanleibie,@RequestParam("jigoumingchengma") String ppJigoumingchengma,@RequestParam("paixu") String ppPaixu,@RequestParam("pageindex") int ppPageIndex,
											@RequestParam("pagesize") int ppPageSize){
		try {
			List<Map<String,Object>> mmList = ddRenyuanService.findCustomRenyuanByvalid(ppDeptId,ppTrueName,ppRenyuanleibie,"",ppJigoumingchengma,ppPaixu,ppPageIndex,ppPageSize);
			List<Map<String,Object>> mmReturnList = new ArrayList<>();
			for (int i = 0; i < mmList.size(); i++) {
				int mmRenyuanHebingshu = 0;
				Map<String,Object> mmMap = mmList.get(i);
				if (mmMap!=null){
					List<Map<String,Object>> mmReturnJiashuList = new ArrayList<>();

					String mmRenyuanId = mmMap.get("renyuanid") == null ? "" : mmMap.get("renyuanid").toString();
					String mmShifoujingshang = "";

					List<Map<String,Object>> mmJiashuList = ddJiashuService.findByRenyuanid(mmRenyuanId);
					for (int j = 0; j < mmJiashuList.size(); j++) {
						int mmjiashuhebing = 0;
						Map<String,Object> mmJiashuMap = mmJiashuList.get(j);

						if (mmJiashuMap!=null){
							mmShifoujingshang = "否";
							String mmJiashuId = mmJiashuMap.get("jiashuid") == null ? "" : mmJiashuMap.get("jiashuid").toString();
							List<Map<String,Object>> mmJingshangqingkuangList = ddService.findVaild(mmJiashuId);
							if (mmJingshangqingkuangList.size()>0){
								mmShifoujingshang = "是";
								mmjiashuhebing = mmJingshangqingkuangList.size();
								mmRenyuanHebingshu = mmRenyuanHebingshu+mmjiashuhebing;
							}else{
								mmRenyuanHebingshu = mmRenyuanHebingshu+1;
							}

							mmJiashuMap.put("jingshanglist",mmJingshangqingkuangList);
							mmJiashuMap.put("shifoujingshang",mmShifoujingshang);
							mmJiashuMap.put("hebinghang",mmjiashuhebing);
							mmReturnJiashuList.add(mmJiashuMap);
						}


					}
					mmMap.put("hebinghang",mmRenyuanHebingshu);
					mmMap.put("jiashujingshanglist",mmReturnJiashuList);
				}
				mmReturnList.add(mmMap);
			}
			Integer mmCount = ddRenyuanService.getCustomCountByvalid(ppDeptId,ppTrueName,ppRenyuanleibie,"",ppJigoumingchengma,ppPageIndex,ppPageSize);
			PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

			Map<String, Object> mmReturnMap = new HashMap<String, Object>();
			mmReturnMap.put("RenyuanList", mmReturnList);
			mmReturnMap.put("PageInfo", mmPageInfo);
			return JsonResult.getSuccessResult(mmReturnMap);
		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/findCustomByDeptId:error " + e.getMessage());
		}
	}

	@RequestMapping("daochu")
	public void daoChu(@RequestParam("deptid") String ppDeptId,@RequestParam("renyuanleibie") String ppRenyuanleibie,@RequestParam("jigoumingchengma") String ppJigoumingchengma,@RequestParam("paixu") String ppPaixu,HttpServletRequest request, HttpServletResponse response){
		try {
			List<Map<String,Object>> mmList = ddRenyuanService.findByDeptId(ppDeptId,ppRenyuanleibie,ppJigoumingchengma,ppPaixu);
			List<Map<String,Object>> mmReturnList = new ArrayList<>();
			Map<String,Object> mmReturnMap = new HashMap<>();
			for (int i = 0; i < mmList.size(); i++) {
				Map<String,Object> mmMap = mmList.get(i);
				Map<String,Object> mmRenturnRenyuanMap=new HashMap<>();
				if (mmMap!=null){
					List<Map<String,Object>> mmReturnJiashuList = new ArrayList<>();

					String mmRenyuanId = mmMap.get("renyuanid") == null ? "" : mmMap.get("renyuanid").toString();
					String mmTruename = mmMap.get("truename") == null ? "" : mmMap.get("truename").toString();
					String mmJigoumingchengma = mmMap.get("jigoumingchengma") == null ? "" : mmMap.get("jigoumingchengma").toString();
					String mmBuzhibie = mmMap.get("buzhibie") == null ? "" : mmMap.get("buzhibie").toString();
					String mmRenyuanleibie = mmMap.get("renyuanleibietext") == null ? "" : mmMap.get("renyuanleibietext").toString();

					String mmChushengnianyue = mmMap.get("chusheng2") == null ? "" : mmMap.get("chusheng2").toString();
					String mmJunxianleibie = mmMap.get("junxianleibietext") == null ? "" : mmMap.get("junxianleibietext").toString();
					String mmJunxiandengji = mmMap.get("junxiandengjitext") == null ? "" : mmMap.get("junxiandengjitext").toString();
					String mmJunxianshijian = mmMap.get("junxianshijian2") == null ? "" : mmMap.get("junxianshijian2").toString();
					String mmZhiwucengji = mmMap.get("zhiwucengjitext") == null ? "" : mmMap.get("zhiwucengjitext").toString();
					String mmZhiwushijian = mmMap.get("zhiwushijian2") == null ? "" : mmMap.get("zhiwushijian2").toString();
					String mmShifoujingshang = "否";
					String mmHebing = "";
					int hebingshu = 0;
					if (ddService.getCountByzhuangtaiAndRenyuanId(mmRenyuanId)>0){
						hebingshu =ddService.getCountByzhuangtaiAndRenyuanId(mmRenyuanId)-1;
						mmShifoujingshang = "是";
					}
					List<Map<String,Object>> mmJiashuList = ddJiashuService.findByRenyuanid(mmRenyuanId);

					String mmHuanhangfu = "";
					if (mmJiashuList.size()==0){
						mmHuanhangfu="</Row><Row ss:Height=\"43\">";
					}

					String mmTianchongge = "";
					if (mmJiashuList.size()==0){
						mmTianchongge = "<Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell>";
					}

					List<JingshangQingkuang> mmShifoujingshangList = ddService.findVaildByRenyuanId(mmRenyuanId);
					if (mmShifoujingshangList.size()==0&&mmJiashuList.size()>0){
						hebingshu = hebingshu-1;
					}

					for (int j = 0; j < mmJiashuList.size(); j++) {
						Map<String,Object> mmJiashuMap = mmJiashuList.get(j);
						if (mmJiashuMap!=null){
							List<Map<String,Object>> mmReturnJingshangList = new ArrayList<>();
							Map<String,Object> mmReturnJiashuMap = new HashMap<>();

							String mmJiashuId = mmJiashuMap.get("jiashuid") == null ? "" : mmJiashuMap.get("jiashuid").toString();
							String mmName = mmJiashuMap.get("name") == null ? "" : mmJiashuMap.get("name").toString();
							String mmGuanxi = mmJiashuMap.get("guanxitext") == null ? "" : mmJiashuMap.get("guanxitext").toString();
							String mmShenfenzhenghao = mmJiashuMap.get("shenfenzhenghao") == null ? "" : mmJiashuMap.get("shenfenzhenghao").toString();


							List<Map<String,Object>> mmJingshangqingkuangList = ddService.findVaild(mmJiashuId);


							if(mmJiashuList.size()>1&&mmJingshangqingkuangList.size()==0){
								hebingshu= hebingshu+1;
							}

							String mmTianchongge2 = "";
							if (mmJingshangqingkuangList.size()==0){
								mmTianchongge2 = "<Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell>";
							}
							for (int k = 0; k < mmJingshangqingkuangList.size(); k++) {
								Map<String,Object> mmJingshangMap = mmJingshangqingkuangList.get(k);

								if (mmJingshangMap!=null) {
									Map<String,Object> mmReturnJingshangMap = new HashMap<>();

									String mmQiyename = mmJingshangMap.get("qiyename") == null ? "" : mmJingshangMap.get("qiyename").toString();
									String mmJingyingfanwei = mmJingshangMap.get("jingyingfanwei") == null ? "" : mmJingshangMap.get("jingyingfanwei").toString();
									String mmJingyingzhuangtai = mmJingshangMap.get("jingyingzhuangtaitext") == null ? "" : mmJingshangMap.get("jingyingzhuangtaitext").toString();
									String mmChuzie = mmJingshangMap.get("renjiaochuzie") == null ? "" : mmJingshangMap.get("renjiaochuzie").toString();
									String mmZhiwu = mmJingshangMap.get("zhiwutext") == null ? "" : mmJingshangMap.get("zhiwutext").toString();
									String mmQianwushangpin = mmJingshangMap.get("qianwushangpinhuofuwuname") == null ? "" : mmJingshangMap.get("qianwushangpinhuofuwuname").toString();
									String mmQianwuduixiang = mmJingshangMap.get("qianwujiaoyiduixiangname") == null ? "" : mmJingshangMap.get("qianwujiaoyiduixiangname").toString();
									String mmShifouzhijieguanxi = mmJingshangMap.get("shifouyouzhijieguanxi") == null ? "" : mmJingshangMap.get("shifouyouzhijieguanxi").toString();
									String mmShijunduimingcheng = mmJingshangMap.get("shijunduimingcheng") == null ? "" : mmJingshangMap.get("shijunduimingcheng").toString();
									String mmJinsanzhijieguanximingcheng = mmJingshangMap.get("jinsanzhijieguanximingcheng") == null ? "" : mmJingshangMap.get("jinsanzhijieguanximingcheng").toString();

									if ("1".equals(mmShifouzhijieguanxi)){
										mmShifouzhijieguanxi = "是";
									}else{
										mmShifouzhijieguanxi = "否";
									}

									String mmZhanwei = "";
									if (k>0){
										mmZhanwei =
												"<Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell>";
									}
									String mmHuanhangfu2 = "";
									if (!((j-1)==mmJiashuList.size()&&(k-1)==mmJingshangqingkuangList.size())){
										mmHuanhangfu2="</Row><Row ss:Height=\"43\">";
									}
									mmReturnJingshangMap.put("zhanwei", mmZhanwei);
									mmReturnJingshangMap.put("qiyename", mmQiyename);
									mmReturnJingshangMap.put("jingyingfanwei", mmJingyingfanwei);
									mmReturnJingshangMap.put("jingyingzhuangtai", mmJingyingzhuangtai);
									mmReturnJingshangMap.put("chuzie", mmChuzie);
									mmReturnJingshangMap.put("zhiwu", mmZhiwu);
									mmReturnJingshangMap.put("qianwushangpin", mmQianwushangpin);
									mmReturnJingshangMap.put("qianwuduixiang", mmQianwuduixiang);
									mmReturnJingshangMap.put("shifouzhijieguanxi", mmShifouzhijieguanxi);
									mmReturnJingshangMap.put("huanhangfu", mmHuanhangfu2);
									mmReturnJingshangMap.put("shijunduimingcheng", mmShijunduimingcheng);
									mmReturnJingshangMap.put("jinsanzhijieguanximingcheng", mmJinsanzhijieguanximingcheng);

									mmReturnJingshangList.add(mmReturnJingshangMap);
								}
							}
							String mmHebing2 = "";
							if (mmReturnJingshangList.size()>0){
								int hebingshu2 = mmReturnJingshangList.size()-1;
								mmHebing2 = "ss:MergeDown=\""+hebingshu2+"\"";
							}

							String mmHuanhang = "";
							if (mmReturnJingshangList.size()==0){
								mmHuanhang = "</Row><Row ss:Height=\"43\">";
							}
							String mmZhanwei = "";
							if (j>0){
								mmZhanwei="<Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell><Cell ss:StyleID=\"s53\"><Data ss:Type=\"String\"></Data></Cell>";
							}

							mmReturnJiashuMap.put("zhanwei",mmZhanwei);
							mmReturnJiashuMap.put("tianchongge",mmTianchongge2);
							mmReturnJiashuMap.put("name",mmName);
							mmReturnJiashuMap.put("guanxi",mmGuanxi);
							mmReturnJiashuMap.put("shenfenzhenghao",mmShenfenzhenghao);
							mmReturnJiashuMap.put("shifoujingshang",mmShifoujingshang);
							mmReturnJiashuMap.put("hebingshu",mmHebing2);
							mmReturnJiashuMap.put("huanhangfu",mmHuanhang);
							mmReturnJiashuMap.put("jingshanglist",mmReturnJingshangList);

							mmReturnJiashuList.add(mmReturnJiashuMap);
						}


					}
					mmHebing = "ss:MergeDown=\""+hebingshu+"\"";

					mmRenturnRenyuanMap.put("tianchongge",mmTianchongge);
					mmRenturnRenyuanMap.put("truename",mmTruename);
					mmRenturnRenyuanMap.put("jigoumingchengma",mmJigoumingchengma);
					mmRenturnRenyuanMap.put("buzhibie",mmBuzhibie);
					mmRenturnRenyuanMap.put("renyuanleibie",mmRenyuanleibie);
					mmRenturnRenyuanMap.put("chushengnianyue",mmChushengnianyue);

					if (!"".equals(mmJunxianshijian)){
						mmRenturnRenyuanMap.put("junxiandengjishijian",mmJunxianleibie+mmJunxiandengji+"&#10;"+mmJunxianshijian.replaceAll("-","."));
					}else {
						mmRenturnRenyuanMap.put("junxiandengjishijian",mmJunxianleibie+mmJunxiandengji);
					}
					if (!"".equals(mmZhiwushijian)){
						mmRenturnRenyuanMap.put("zhiwucengjishijian",mmZhiwucengji+"&#10;"+mmZhiwushijian.replaceAll("-","."));
					}else {
						mmRenturnRenyuanMap.put("zhiwucengjishijian",mmZhiwucengji);
					}

					mmRenturnRenyuanMap.put("hebingshu",mmHebing);
					mmRenturnRenyuanMap.put("shifoujingshang",mmShifoujingshang);
					mmRenturnRenyuanMap.put("xuhao",i+1);
					mmRenturnRenyuanMap.put("huanhangfu",mmHuanhangfu);
					mmRenturnRenyuanMap.put("jiashujingshanglist",mmReturnJiashuList);
				}
				mmReturnList.add(mmRenturnRenyuanMap);
			}
			mmReturnMap.put("renyuanjiashujingshanglist",mmReturnList);
			if (userfilepath.endsWith("/")) {
				userfilepath = userfilepath.substring(0, userfilepath.length() - 1);
			}
			SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			String mmSavePath = userfilepath + "/temp/jingshangqingkuang/"+mmDateFormat.format(new Date())+"/";
			File mmFold = new File(mmSavePath);
			if (!mmFold.isDirectory() || !mmFold.exists()) {
				mmFold.mkdirs();
			}

			CreateWord.createWord(userfilepath, mmSavePath,  "huizongbiao.xlsx", mmReturnMap, request,
					response,"js","1");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
    
    @RequestMapping("find_vaild_by_renyuanid")
    public JsonResult<?> findvaildByRenyuanId(@RequestParam("renyuanId") String pprenyuanID){
        try {

            return JsonResult.getSuccessResult(ddService.findVaildByRenyuanId(pprenyuanID));

        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.getErrorResult("jingshangqingkuang/findvaild:error " + e.getMessage());
        }
    }

	@RequestMapping("find_vaild_by_jiashuid")
	public JsonResult<?> findvaildByJiashuId(@RequestParam("jiashuid") String ppJiashuID){
		try {

			return JsonResult.getSuccessResult(ddService.findVaildByJiashuId(ppJiashuID));

		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/findvaild:error " + e.getMessage());
		}
	}

	@RequestMapping("find_by_shenfenzheng_and_shehuixinyongdaima")
	public JsonResult<?> findbyshenfenzhenghaoandShehuixinyongdaima(@RequestParam("shenfenzhenghao") String ppShenfenzhenghao,@RequestParam("shehuixinyongdaima") String ppShehuixinyongdaima){
		try {

			return JsonResult.getSuccessResult(ddService.findbyshenfenzhenghaoandShehuixinyongdaima(ppShenfenzhenghao,ppShehuixinyongdaima));

		} catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/findvaild:error " + e.getMessage());
		}
	}

	@RequestMapping("find_lingdao_all_jingshang")
	public JsonResult<?> findLingdaoAllJingshang(@RequestParam("renyuanid") String ppRenyuanID) {
		try {
			List<Map<String,Object>> mmJingshangbanqiyejiashuList = ddService.findJiashuByRenyuanIdAndLeixing(ppRenyuanID,"1");
			List<Map<String,Object>> mmReturningshangbanqiyeList = new ArrayList<>();
			for (int i = 0; i < mmJingshangbanqiyejiashuList.size(); i++) {
				Map<String,Object> mmJiashuMap = mmJingshangbanqiyejiashuList.get(i);
				if (mmJiashuMap!=null){
					String mmJiashuId = mmJiashuMap.get("jiashuid")== null ? "" :mmJiashuMap.get("jiashuid").toString();
					List<Map<String,Object>> mmJingshangqingkuangList = ddService.findByJiashuIdAndLeixing(mmJiashuId,"1");
					mmJiashuMap.put("jingshangqingkuanglist",mmJingshangqingkuangList);
					mmJiashuMap.put("hebing",mmJingshangqingkuangList.size());
				}
				mmReturningshangbanqiyeList.add(mmJiashuMap);
			}

			List<Map<String,Object>> mmYouchangzhongjiejiashuList = ddService.findJiashuByRenyuanIdAndLeixing(ppRenyuanID,"2");

			List<Map<String,Object>> mmReturnouchangzhongjiejiashuList = new ArrayList<>();
			for (int i = 0; i < mmYouchangzhongjiejiashuList.size(); i++) {
				Map<String,Object> mmJiashuMap = mmYouchangzhongjiejiashuList.get(i);
				if (mmJiashuMap!=null){
					String mmJiashuId = mmJiashuMap.get("jiashuid")== null ? "" :mmJiashuMap.get("jiashuid").toString();
					List<Map<String,Object>> mmJingshangqingkuangList = ddService.findByJiashuIdAndLeixing(mmJiashuId,"2");
					mmJiashuMap.put("jingshangqingkuanglist",mmJingshangqingkuangList);
					mmJiashuMap.put("hebing",mmJingshangqingkuangList.size());
				}
				mmReturnouchangzhongjiejiashuList.add(mmJiashuMap);
			}
			List<Object> mmRenyuanList = new ArrayList<>();
			Renyuan mmRenyuan = ddRenyuanService.findOne(ppRenyuanID);
			mmRenyuanList.add(mmRenyuan);

			Map<String,Object> mmMap = new HashMap<>();
			mmMap.put("jingshangbanqiyelist",mmReturningshangbanqiyeList);
			mmMap.put("youchangzhongjielist",mmReturnouchangzhongjiejiashuList);
			mmMap.put("renyuanlist",mmRenyuanList);

			return JsonResult.getSuccessResult(mmMap);
		}catch (Exception e) {
			e.printStackTrace();
			return JsonResult.getErrorResult("jingshangqingkuang/findLingdaoAllJingshang:error " + e.getMessage());
		}
	}

    @RequestMapping("delete")
    public JsonResult<?> delete(@RequestParam("id") String ppID) {
        try {
            return ddService.delete(ppID) == true ? JsonResult.getSuccessResult("删除经商情况信息成功")
                    : JsonResult.getErrorResult("删除经商情况信息失败");
        }catch (Exception e) {
            e.printStackTrace();
            return JsonResult.getErrorResult("renyuan/delete:error " + e.getMessage());
        }
    }
    
    @RequestMapping("huizongbiao")
	public void adminHuizongbiao(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

		List<List<String>> mmResultList = new ArrayList<List<String>>(); 
		List<String> mmTitleList = new ArrayList<String>(); 

		mmTitleList.add("序号");
		mmTitleList.add("姓名"); 
		mmTitleList.add("身份证号"); 
		mmTitleList.add("经商类型"); 
		mmTitleList.add("企业名称"); 
		mmTitleList.add("经营范围");
		mmTitleList.add("经营状态");
		mmTitleList.add("认缴出资额（万元）"); 
		mmTitleList.add("在企业所任职务"); 
		mmTitleList.add("近三年排在前5名的销售商品或服务名称"); 
		mmTitleList.add("近三年排在前5名的交易对象名称");
		mmTitleList.add("是否与本人所在单位有直接关系");

		mmResultList.add(mmTitleList);

		List<JingshangQingkuang> mmHuizongbiaoList = ddService.findAll();

		int mmRenyuanshu = mmHuizongbiaoList.size(); 
		if(mmRenyuanshu > 0) { 
			for(int i = 0; i <mmRenyuanshu; i++) { 
				JingshangQingkuang mmHuizongbiao = mmHuizongbiaoList.get(i); 
				String mmXuhao = String.valueOf(i + 1); 
//				String mmXingming = mmHuizongbiao.getJiashuname() == null ? "" : mmHuizongbiao.getJiashuname().toString();
//				String mmShenfenzhenghao = mmHuizongbiao.getShenfenzhenghao() == null ? "" :mmHuizongbiao.getShenfenzhenghao().toString();
//				String mmJingshangleixing = mmHuizongbiao.getLeixingText() == null ? "" :mmHuizongbiao.getLeixingText().toString();
				String mmQiyemingcheng = mmHuizongbiao.getQiyename() == null ? "" :mmHuizongbiao.getQiyename().toString();
				String mmJingyingfanwei = mmHuizongbiao.getJingyingfanwei() == null ? "" :mmHuizongbiao.getJingyingfanwei().toString();
//				String mmJingyingzhuangtai = mmHuizongbiao.getJingyingzhuangtaiText() == null ? "" :mmHuizongbiao.getJingyingzhuangtaiText().toString();
				String mmChuzie =mmHuizongbiao.getRenjiaochuzie() == null ? "" :mmHuizongbiao.getRenjiaochuzie().toString();
//				String mmZhiwu = mmHuizongbiao.getZhiwuText()  == null ? "" :mmHuizongbiao.getZhiwuText().toString() ;
				String mmQianwuShangpin = mmHuizongbiao.getQianwushangpinhuofuwuname() == null ? "" :mmHuizongbiao.getQianwushangpinhuofuwuname().toString();
				String mmQianwuJiaoyiduixiang = mmHuizongbiao.getQianwujiaoyiduixiangname() == null ? "" :mmHuizongbiao.getQianwujiaoyiduixiangname().toString();
				String mmShifouZhijieguanxi = mmHuizongbiao.getShifouyouzhijieguanxi() == null ? "" : mmHuizongbiao.getShifouyouzhijieguanxi().toString();
				


				List<String> mmRenyuanList = new ArrayList<String>();
				mmRenyuanList.add(mmXuhao);
//				mmRenyuanList.add(mmXingming);
//				mmRenyuanList.add(mmShenfenzhenghao);
//				mmRenyuanList.add(mmJingshangleixing);
				mmRenyuanList.add(mmQiyemingcheng); 
				mmRenyuanList.add(mmJingyingfanwei);
//				mmRenyuanList.add(mmJingyingzhuangtai);
				mmRenyuanList.add(mmChuzie); 
//				mmRenyuanList.add(mmZhiwu);
				mmRenyuanList.add(mmQianwuShangpin); 
				mmRenyuanList.add(mmQianwuJiaoyiduixiang);
				mmRenyuanList.add(mmShifouZhijieguanxi);

				mmResultList.add(mmRenyuanList); 
			} 
		}

		try { 
			//取出文档存放的根目录，并去除文件最后的斜杠 
			if (userfilepath.endsWith("/")) { 
				userfilepath = userfilepath.substring(0, userfilepath.length()-1); 
			}

			SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd");
			String mmSavePath = userfilepath +  "/temp/jingshangjianguan/jingshangqingkuang/"+mmDateFormat.format(new Date()) + "/";

			CreateXLS.createExcel(mmResultList, mmSavePath,  "AllJingshangqingkuang.xls",
					"huizongbiao", request, response); 

		} 
		catch (Exception e) { 
			logger.error("JingshangQingkuangController -> huizongbiao: "+e.getMessage());
		}

	}


}
